package com.jzoom.zoom.admin.controllers;

import com.jzoom.zoom.common.annotations.Inject;
import com.jzoom.zoom.dao.Dao;
import com.jzoom.zoom.web.annotations.Controller;
import com.jzoom.zoom.web.annotations.Mapping;
import com.jzoom.zoom.web.annotations.Param;
import com.jzoom.zoom.web.exception.StatusException;
import com.jzoom.zoom.web.view.impl.StringView;

@Controller(key="public")
public class ContentController {

    @Inject(value = "admin")
    private Dao admin;


    @Mapping("{key}")
    public StringView index(

            @Param(pathVariable = true)
            String key
    ){

        String content = admin.ar()
                .table("sys_page")
                .where("url","public/"+key)
                .getValue("template",String.class);
        if(content==null){
            throw new StatusException.NotFoundException();
        }
        return new StringView(content);

    }



}
